import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    AddDataButton,
    ModDataButton,
    DelDataButton,
    ExecuteButton,
    SynchronizeButton,
    OpenExcelButton,
} from '../Common/options'

export const ScoreManagement001 = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '项目评分',
        pageSize: 10,
        params: { pageIndex: 1, scoreType: 1, OrderField: 'yearMonth@desc,projectUuid@asc' },
        get: API_LIST()[`getScoreManagement`],
        added: `posScoreManagement`,
        modify: `putScoreManagement`,
        delete: `delScoreManagement`,
        initialValues: { scoreType: 1 },
        options: [
            <OpenExcelButton
                key="two"
                title="批量导入"
                OptionsEvent={OptionsEvent}
                data={{
                    save: true,
                    submit: true,
                    url: 'getScoreManagementInfo',
                    pos: 'posUploadScoreManagement',
                    ScoreType: 1,
                }}
            />,
            Permission.findIndex(v => v.uuid === 'dfc3f929-cab5-4a46-ab67-f198a6323638') !== -1 && (
                <SynchronizeButton
                    title="上传评分"
                    type="primary"
                    smallTitle="上传项目评分"
                    OptionsEvent={OptionsEvent}
                    data={{
                        url: 'posBCCenterPushPushScoreManagement',
                        type: 1,
                    }}
                />
            ),
            Permission.findIndex(v => v.uuid === '42e46887-5bea-4dd7-a2ef-07dbbd2993f0') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            {
                dataIndex: 'scoreType',
                title: '评分类型',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
            },
            commonTableList.uuid,
            {
                dataIndex: 'projectUuid',
                title: '项目名称',
                valueType: 'select',
                valueEnum: ClientData.project,
                rules: true,
                width: 220,
                hideInTable: true,
            },
            {
                dataIndex: 'projectName',
                title: '项目名称',
                valueType: 'input',
                rules: true,
                width: 150,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
            },

            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                picker: 'month',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'organizationUuid',
                title: '组织机构',
                valueType: 'select',
                valueEnum: ClientData.organization,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'organizationScore',
                title: '评分',
                valueType: 'input',
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'projectScore',
                title: '项目总评分',
                valueType: 'input',
                rules: true,
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'isEnabled',
                title: '审核状态',
                valueType: 'select',
                valueEnum: BuiltInData.Pass,
                rules: true,
                width: 150,
                hideInAdded: true,
                hideInModify: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 250,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, projectUuid, yearMonth, scoreType, isEnabled } = record
                    const statusText = isEnabled === 0 ? '通过' : '不通过'
                    const tipsText = `${statusText}成功!`
                    return [
                        Permission.findIndex(v => v.uuid === '57031e08-5d60-41d6-9fbf-c272d6b3fef5') !== -1 &&
                            isEnabled === 0 && (
                                <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                            ),
                        Permission.findIndex(v => v.uuid === 'fdde15e2-0e26-49b4-b651-186147f41bc5') !== -1 && (
                            <ExecuteButton
                                actionRef={actionRef}
                                key="one"
                                title={statusText}
                                danger={isEnabled}
                                url="posScoreManagementUpdateIsEnabled"
                                path={[projectUuid, yearMonth, isEnabled === 0 ? 1 : 0, scoreType]}
                                tips={tipsText}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '91de8985-20d5-4393-a5e5-1ffd5f25b14f') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="ScoreManagement"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
